#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e5+10;
int a[N];
int b[N];
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	IOS;
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int st[3]={0};
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		for(int i=1;i<=n;i++)
		{
			cin>>b[i];
		}
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0 && b[i]==0) continue;
			int g=0; 
			if(a[i]<b[i]) g=gcd(b[i],a[i]);
			else g=gcd(a[i],b[i]);
			a[i]/=g, b[i]/=g;
			
			if(a[i]%2==1 && b[i]%2==0) st[0]=1;
			else if(a[i]%2==0 && b[i]%2==1) st[1]=1;
			else st[2]=1;
		}
		if(st[1]+st[0]+st[2]==1 || st[1]+st[0]+st[2]==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}

